<!-- 首页 -->
<template lang="html">
  <div class="index">
    <!-- 正在进行 -->
    <underway hidePage :pageSize="5" />

    <!-- 项目查询 -->
    <projectQuery hidePage hideCompleted :pageSize="5" :showHeight='300' />

    <!-- 日历 -->
    <div id="rili">
      <img @click="showRili" src="../../assets/images/rili.png" alt="">
    </div>
    <Drawer :mask="false" width="300" closable :closable="false" v-model="value1">
      <Input style="margin: 10px 0" v-model="CalendarData.xzsj" icon="ios-clock-outline">
      </Input>
      <Calendar style="margin: 10px 0" :sundayStart="true" :markDate='rlarr' v-on:choseDay="clickDay" v-on:changeMonth="changeDate">
      </Calendar>
      <Row style="margin: 10px 0">
        <Col style="text-align:right">
        <Button @click="clearData">清空</Button>
        <Button type="primary" @click="value1 = false">确定</Button>
        </Col>
      </Row>
    </Drawer>
    <Modal v-model="modalText" title="日历消息提示">
      <div slot="footer">
        <Button type="error" :disabled="CalendarData.delState" size="large" @click="delText">删除</Button>
        <Button type="primary" :disabled="CalendarData.updataState" size="large" @click="updataText">修改</Button>
        <Button type="primary" :disabled="CalendarData.addState" size="large" @click="addText">添加</Button>
      </div>
      <Input v-model="CalendarData.modalTextVal" type="textarea" :rows="4" placeholder="请输入内容..." />
    </Modal>
    
  </div>
</template>

<script>
  import underway from "../myproject/underway";
  import projectQuery from "../myproject/projectQuery";
  import Calendar from "vue-calendar-component";
  export default {
    components: {
      underway,
      projectQuery,
      Calendar
    },
    data() {
      return {
        value1: false,
        rlarr: [],
        allData: {},
        modalText: false,
        CalendarData: {
          delState: true,
          addState: true,
          updataState: true
        }
      };
    },
    created() {
      
      this.$post("RemarkMember.remark",{
        Remark: "eao"
      })

      axios.post("schedule/thisTime").then((res)=>{
        if(res.data){
          this.$Notice.info({
            title: '今日日程',
            desc: res.data[0].Content,
            top: 50,
            duration: 3
          });
        }
      })
        axios.post("member/message").then((res)=>{
            console.log(res)
        });
        // if(parent.document.getElementById("iframeId")){
        //     parent.document.getElementById("iframeId").style= "display:none";
        //     parent.location.reload()
        // }
      // axios.get("http://api.ahjdev.top/member/islogin")
      axios.get("/member/islogin")
      .then(res => {
        if(res._STATUS==0){
            this.$router.push({
              name: 'login'
            })
        }else{
           axios.post("/member/identifier/lookup",{
             identifier:res.Mobile
           }).then((res)=>{
                // this.$router.go(0)
            })
        }
      });
      this.CalendarData.xzsj = this.$moment().format("YYYY-MM-DD")
    },
    methods: {
      userOrgOk(){

      },
      clearData() {
        axios.get('/schedule/clearData', {
          params: {
            Month: this.$moment().format("YYYY-MM")
          }
        }).then(res => {
          console.log(res)
          this.$Message.success(res._MESSAGE)
          this.showRili()
        })
      },
      addText() {
        console.log(this.CalendarData)
        if (this.CalendarData.modalTextVal != "") {
          axios.get('schedule/insert', {
            params: {
              Content: this.CalendarData.modalTextVal,
              DoTime: this.CalendarData.xzsj
            }
          }).then(res => {
            let title = res._MESSAGE
            if (res._STATUS == 1) {
              this.modalText = false
              this.showRili()
            }
            this.$Message.success(title)
          })
        } else {
          this.$Modal.error({
            title: '请选择您的进程内容'
          })
        }
      },
      updataText() {
        console.log(this.CalendarData)
        axios.get('/schedule/update', {
          params: {
            id: this.CalendarData.id,
            Content: this.CalendarData.modalTextVal
          }
        }).then(res => {
          let title = res._MESSAGE
          if (res._STATUS == 1) {
            this.modalText = false
            this.showRili()
          }
        })
      },
      delText() {
        console.log(this.CalendarData)
        axios.get('/schedule/delete', {
          params: {
            id: this.CalendarData.id
          }
        }).then(res => {
          let title = res._MESSAGE
          if (res._STATUS == 1) {
            this.modalText = false
            this.showRili()
          }
        })
      },
      showRili() {
        this.value1 = true;
        axios
          .get("/schedule/selectAll", {
            params: {
              Month: this.$moment().format("YYYY-MM")
            }
          })
          .then(res => {
            let rlArr = []
            console.log(res);
            this.allData = res.data
            res.data.forEach((e, i) => {
              if (e) {
                rlArr.push(e.DoTime.split(" ")[0])
              }
            });
            this.rlarr = rlArr
          });
      },
      getThisTime(method, params) {

      },
      clickDay(data) {
        this.CalendarData.xzsj = this.$moment(data).format("YYYY-MM-DD");
        axios.get('/schedule/findTime', {
          params: {
            DoTime: this.CalendarData.xzsj
          }
        }).then(res => {
          console.log(res)
          if (res._STATUS == 1) {
            this.CalendarData.delState = false
            this.CalendarData.modalTextVal = res.data[0].Content
            this.CalendarData.id = res.data[0].Id
            if (this.CalendarData.modalTextVal != "") {
              this.CalendarData.addState = true
              this.CalendarData.updataState = false
            }
          } else {
            this.CalendarData.delState = true
            this.CalendarData.addState = false
            this.CalendarData.updataState = true
            this.CalendarData.modalTextVal = ""
          }
        })
        this.modalText = true
      },
      changeDate(data) {
        console.log(data); //左右点击切换月份
      }
    }
  };
</script>

<style lang="less">
  #rili {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 100;
  }

  .ivu-drawer {
    height: 500px !important;
    bottom: 0;
    display: block;
    top: initial !important;

    .ivu-drawer-body {
      overflow: initial;
      position: relative;
      background: #f3f3f4;

      .wh_item_date:hover {
        background: #cccccc;
        cursor: pointer;
      }

      .wh_content_all {
        background: #fff;

        .wh_content .wh_content_item,
        .wh_top_changge li {
          color: black;

          .wh_jiantou1 {
            border-top: 2px solid #cccccc;
            border-left: 2px solid #cccccc;
          }

          .wh_jiantou2 {
            border-top: 2px solid #cccccc;
            border-right: 2px solid #cccccc;
          }

          .wh_isToday {
            background: #2d8cf0;
            border: 1px solid #2d8cf0;
            color: #ffffff;
          }
        }

        .wh_content_item>.wh_isMark {
          background: #2d8cf0;
          border: 1px solid #2d8cf0;
        }
      }
    }

    .ivu-drawer-body::before {
      position: absolute;
      left: -50px;
      color: #ffffff;
      text-align: center;
      font-size: 20px;
      top: 0;
      content: "日程";
      width: 50px;
      background: #2d8cf0;
      height: 100px;
      z-index: 1001;
      border-top-left-radius: 10px;
      border-bottom-left-radius: 10px;
      padding: 10px;
    }
  }
</style>
